'Medium-Large', 'wide_large' => 'Wide Large', 'wide_medium' => 'Wide Medium', 'wide_small' => 'Wide Small' ) ); } add_filter('image_size_names_choose', 'custom_wide_size'); // Force-disable Month/Year Uploads update_option('uploads_use_yearmonth_folders', false); /*-------------------------------*\ LOG IN \*-------------------------------*/ // Login Logo Image function login_logo() { ?> 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'size' => 'thumbnail', 'include' => '', 'exclude' => '' ), $attr)); $id = intval($id); if ('RAND' == $order) $orderby = 'none'; if (!empty($include)) { $include = preg_replace('/[^0-9,]+/', '', $include); $_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby)); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } if (empty($attachments)) return ''; // Output $output = "
\n"; // Now loop through each attachment foreach ($attachments as $id => $attachment) { $img = wp_get_attachment_image_src($id, 'full'); $thumb = wp_get_attachment_image_src($id, 'thumbnail'); $caption = wptexturize($attachment->post_excerpt); $output .= "\"\"\n"; } $output .= "
\n"; $output .= wp_enqueue_script('baguetteBox', get_template_directory_uri() . '/js/lib/baguetteBox.min.js', false, null, true); wp_add_inline_script('baguetteBox', 'baguetteBox.run(".gallery");'); wp_enqueue_style('baguetteBox', get_template_directory_uri() . '/css/lib/baguetteBox.min.css', false, null); return $output; } add_filter('post_gallery', 'my_post_gallery', 10, 2); /*-------------------------------*\ ADMIN \*-------------------------------*/ /* Disable the Admin Bar outside the Dashboard as it can interfere if the theme has a "sticky" navigation. */ show_admin_bar(false); // Custom Dashboard CSS function custom_dashboard_css() { // For Everyone echo ''; // For Admin if (current_user_can('administrator')) { echo ''; } // For Editor if (!current_user_can('administrator')) { echo ''; } } add_action('admin_head', 'custom_dashboard_css'); // Remove "Thank you for creating with WordPress." From Admin Footer function change_footer_admin() { echo ''; } add_filter('admin_footer_text', 'change_footer_admin'); // Remove "Howdy" From Admin Bar function replace_howdy($wp_admin_bar) { $my_account=$wp_admin_bar->get_node('my-account'); $newtitle = str_replace('Howdy,', 'Logged In:', $my_account->title); $wp_admin_bar->add_node(array( 'id' => 'my-account', 'title' => $newtitle, ) ); } add_filter('admin_bar_menu', 'replace_howdy', 25); // Remove Feature Support function remove_feature_support() { // Comments remove_post_type_support('post', 'comments'); remove_post_type_support('page', 'comments'); remove_post_type_support('attachment', 'comments'); // Trackbacks remove_post_type_support('post', 'trackbacks'); // Custom Fields remove_post_type_support('post', 'custom-fields'); remove_post_type_support('page', 'custom-fields'); // Excerpt remove_post_type_support('post', 'excerpt'); // Revisions remove_post_type_support('post', 'revisions'); } add_action('init', 'remove_feature_support', 100); // Hide "Help" tab function remove_help_tabs( $old_help, $screen_id, $screen ) { $screen->remove_help_tabs(); return $old_help; } add_filter('contextual_help', 'remove_help_tabs', 999, 3); // Hide the Dashboard and Redirect to New Page Screen add_action('admin_init', function () { global $pagenow; // Get current page $redirect = get_admin_url(null, 'edit.php?post_type=page' ); if ($pagenow == 'index.php') { wp_redirect( $redirect, 301 ); exit; } }); // Clean Admin Bar add_action('admin_bar_menu', function ($admin_bar) { $admin_bar->remove_menu('wp-logo'); $admin_bar->remove_menu('view-site'); $admin_bar->remove_menu('comments'); // $admin_bar->remove_menu('new-post'); }, 999); // Remove Admin Menus function remove_admin_menus() { // Hide Dashboard remove_menu_page('index.php'); // Hide Posts // remove_menu_page('edit.php'); // Hide Plug-ins remove_menu_page('plugins.php'); // Hide Tools remove_menu_page('tools.php'); // Hide Comments Menu remove_menu_page('edit-comments.php'); // Hide Media Menu remove_submenu_page('options-general.php', 'options-media.php'); // Hide Writing Menu remove_submenu_page('options-general.php', 'options-writing.php'); // Hide Discussion Menu remove_submenu_page('options-general.php', 'options-discussion.php'); // Remove Themes and Settings for Editors if (!current_user_can('administrator')) { remove_submenu_page('options-general.php', 'options-general.php'); remove_submenu_page('options-general.php', 'options-reading.php'); remove_submenu_page('options-general.php', 'options-permalink.php'); global $submenu; unset($submenu['themes.php'][5]); } } add_action('admin_menu', 'remove_admin_menus'); // Custom Admin Menu Order function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'edit.php?post_type=page', // Pages 'edit.php', // Posts 'upload.php', // Media 'themes.php', // Appearance 'users.php', // Users // 'plugins.php', // Plugins 'options-general.php', // Settings ); } add_filter('custom_menu_order', 'custom_menu_order'); add_filter('menu_order', 'custom_menu_order'); // Remove Options in WP Customizer That are Dangerous for Clients function remove_customizer_options( $wp_customize ) { $user = wp_get_current_user(); if (!$user->has_cap('administrator')) { $wp_customize->remove_section('static_front_page'); $wp_customize->remove_section('custom_css'); } } add_action('customize_register', 'remove_customizer_options', 15); // Allow SVG Uploads function wpcontent_svg_mime_type($mimes = array()) { $mimes['svg'] = 'image/svg+xml'; $mimes['svgz'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'wpcontent_svg_mime_type'); /*-------------------------------*\ FEATURED IMAGES \*-------------------------------*/ add_theme_support('post-thumbnails', array('post')); /*-------------------------------*\ USER ROLES \*-------------------------------*/ // Hide Roles other than Admin and Editor function exclude_role($roles) { if (isset($roles['author'])) { unset($roles['author']); } if (isset($roles['subscriber'])) { unset($roles['subscriber']); } if (isset($roles['contributor'])) { unset($roles['contributor']); } return $roles; } add_filter('editable_roles', 'exclude_role'); // Let Editors Manage Users and Change Navigation */ function editor_manage_users() { if (get_option('add_cap_editor') != 'done' ) { $edit_editor = get_role('editor'); $edit_editor->add_cap('edit_users'); $edit_editor->add_cap('list_users'); $edit_editor->add_cap('create_users'); $edit_editor->add_cap('add_users'); $edit_editor->add_cap('delete_users'); $edit_editor->add_cap('edit_theme_options'); update_option('add_cap_editor', 'done'); } } add_action('init', 'editor_manage_users'); // Prevent editor from deleting, editing, or creating an administrator class Editor_User_Caps { // Add our filters function __construct() { add_filter( 'editable_roles', array(&$this, 'editable_roles')); add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4); } // Remove 'Administrator' from the list of roles if the current user is not an admin function editable_roles( $roles ){ if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){ unset( $roles['administrator']); } return $roles; } // If someone is trying to edit or delete an // admin and that user isn't an admin, don't allow it function map_meta_cap( $caps, $cap, $user_id, $args ){ switch( $cap ){ case 'edit_user': case 'remove_user': case 'promote_user': if( isset($args[0]) && $args[0] == $user_id ) break; elseif( !isset($args[0]) ) $caps[] = 'do_not_allow'; $other = new WP_User( absint($args[0]) ); if( $other->has_cap( 'administrator' ) ){ if(!current_user_can('administrator')){ $caps[] = 'do_not_allow'; } } break; case 'delete_user': case 'delete_users': if( !isset($args[0]) ) break; $other = new WP_User( absint($args[0]) ); if( $other->has_cap( 'administrator' ) ){ if(!current_user_can('administrator')){ $caps[] = 'do_not_allow'; } } break; default: break; } return $caps; } } $editor_user_caps = new Editor_User_Caps(); // Hide all administrators from user list if not admin function hide_user_query($user_search) { $user = wp_get_current_user(); if (!current_user_can('edit_themes')) { global $wpdb; $user_search->query_where = str_replace('WHERE 1=1', "WHERE 1=1 AND {$wpdb->users}.ID IN ( SELECT {$wpdb->usermeta}.user_id FROM $wpdb->usermeta WHERE {$wpdb->usermeta}.meta_key = '{$wpdb->prefix}capabilities' AND {$wpdb->usermeta}.meta_value NOT LIKE '%administrator%')", $user_search->query_where ); } } add_action('pre_user_query','hide_user_query'); /*-------------------------------*\ CLEAN BODY CLASS \*-------------------------------*/ // Because the default body_class() is messy function clean_body_class() { global $post; echo str_replace('.php', '', get_page_template_slug()); if ($post->post_title) { $title = strtolower($post->post_title); $page_title = str_replace(' ', '-', $title); } if (is_home() ) { echo ' page-blog'; } if (is_front_page() ) { echo ' page-home'; } if (!is_home() && !is_front_page()) { if (is_page()) { echo ' page-' . $page_title; } if (is_singular('post')) { echo ' post-' . $page_title; } if (is_404()) { echo ' page-404'; } if (is_archive() && !is_tax()) { echo ' page-archive'; } if (is_tax()) { echo ' page-taxonomy'; } } } /*-------------------------------*\ ADMIN BODY CLASS \*-------------------------------*/ add_filter('admin_body_class', function($classes) { // Add Current User Role global $current_user; if (is_array($current_user->roles)) { foreach($current_user->roles as $role) { $classes .= "user_role_{$role} "; } } // Add Always-Folded Menu $classes .= ' folded '; return rtrim($classes); }); /*-------------------------------*\ CLEAN HEAD \*-------------------------------*/ remove_action('wp_head', 'rsd_link'); remove_action('wp_head', 'wlwmanifest_link'); remove_action('wp_head', 'wp_generator'); remove_action('wp_head', 'wp_shortlink_wp_head'); remove_action('wp_head', 'rel_canonical'); remove_action('wp_head', 'feed_links_extra', 3); remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); remove_action('wp_head', 'wp_site_icon', 99); remove_action('wp_head', 'rest_output_link_wp_head', 10); remove_action('wp_head', 'wp_resource_hints', 2); /*-------------------------------*\ CLEAN NAVIGATION \*-------------------------------*/ // Remove Ugly Generated Classes function custom_wp_nav_menu($var) { return is_array($var) ? array_intersect($var, array( // List of Allowed Menu Classes 'current-menu-item', 'menu-item-has-children', 'btn-nav' )) : ''; } add_filter('nav_menu_css_class', 'custom_wp_nav_menu'); add_filter('nav_menu_item_id', 'custom_wp_nav_menu'); add_filter('page_css_class', 'custom_wp_nav_menu'); // Renames Classes with Shorter Alternatives function shorter_classes($text){ $replace = array( 'current-menu-item' => 'current', 'menu-item-has-children' => 'parent', ); $text = str_replace(array_keys($replace), $replace, $text); return $text; } add_filter('wp_nav_menu', 'shorter_classes'); /*-------------------------------*\ CLEAN FRONT-END \*-------------------------------*/ // Remove the WordPress Version from RSS Feeds add_filter('the_generator', '__return_false'); // Remove Inline Width Style Added by WordPress to WYSIWYG Image Captions function fixed_img_caption_shortcode($attr, $content = null) { if (!isset($attr['caption'])) { if (preg_match('#((?:]+>s*)?]+>(?:s*)?)(.*)#is', $content, $matches)) { $content = $matches[1]; $attr['caption'] = trim( $matches[2] ); } } $output = apply_filters('img_caption_shortcode', '', $attr, $content); if ($output != '') return $output; extract(shortcode_atts(array( 'id' => '', 'align' => 'alignnone', 'width' => '', 'caption' => '' ), $attr)); if (1 > (int) $width || empty($caption)) return $content; if ($id) $id = 'id="' . esc_attr($id) . '" '; return '
' . do_shortcode($content) . '

' . $caption . '

'; } add_shortcode('wp_caption', 'fixed_img_caption_shortcode'); add_shortcode('caption', 'fixed_img_caption_shortcode'); /*-------------------------------*\ DISABLE EMOJI \*-------------------------------*/ add_action('init', function () { remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); remove_action('admin_print_scripts', 'print_emoji_detection_script'); remove_action('admin_print_styles', 'print_emoji_styles'); remove_filter('the_content_feed', 'wp_staticize_emoji'); remove_filter('comment_text_rss', 'wp_staticize_emoji'); remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); add_filter('emoji_svg_url', '__return_false'); // Filter to remove TinyMCE emojis add_filter('tiny_mce_plugins', function ($plugins) { if (is_array($plugins)) { return array_diff($plugins, array('wpemoji')); } return array(); }); }); /*-------------------------------*\ SHORTCODES \*-------------------------------*/ // iframe function iframe($atts) { extract(shortcode_atts(array( 'src' => "", 'width' => "100%", 'height' => "1200px", 'class' => "" ), $atts)); $iframe = ''; return $iframe; } add_shortcode('iframe', 'iframe'); /*-------------------------------*\ MISC \*-------------------------------*/ // Force WordPress Admin to 1 column function so_screen_layout_columns($columns) { $columns['page'] = 1; return $columns; } add_filter('screen_layout_columns', 'so_screen_layout_columns'); // Redirect Useless Attachment Page to Parent Page function attachment_redirect() { global $post; if (is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0)) { wp_redirect(get_permalink($post->post_parent ), 301); exit(); } } add_action('template_redirect', 'attachment_redirect'); // Disable WordPress API function only_allow_logged_in_rest_access($access) { if(!is_user_logged_in()) { return new WP_Error('rest_cannot_access', 'Only authenticated users can access the REST API.', array('status' => rest_authorization_required_code())); } return $access; } add_filter('rest_authentication_errors', 'only_allow_logged_in_rest_access'); // Auto Update WordPress add_filter('allow_major_auto_core_updates', '__return_true'); // Auto Update Plug-Ins add_filter('auto_update_plugin', '__return_true');